from datetime import datetime

from pymongo import MongoClient


class connect_Mongo(object):
    def __init__(self):
        self.client = MongoClient()
        self.db = self.client['runoob']

    def add_one(self):
        post = {
            'title' : 'biaoti',
            'content' : 'neirong',
            'created_at' : datetime.now()
        }
        return self.db.runoob.insert_one(post)

    def update(self):

        return self.db.runoob.update_one()

    def find_one(self):
        return self.db.runoob.find_one()

    # def find_all(self,find_txt):
    #     return self.db.runoob.find({'%s':True}) %find_txt

    def find_all(self):
        return self.db.runoob.find()


    def delete(self):
        return self.db.runoob.delete_one()
        # self.sb.runoob.delete()

def main():
    obj = connect_Mongo()
    # insert_txt = input()
    rest = obj.add_one()
    # rest = obj.update()
    # print(rest.inserted_id)
    # rest = obj.find_all(insert_txt)
    for i in rest:
        print(i)

if __name__ == '__main__':
    main()
